package com.dgcsxy.cat_eyes_movies.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dgcsxy.cat_eyes_movies.common.utils.ResponseResult;
import com.dgcsxy.cat_eyes_movies.dao.UserMapper;
import com.dgcsxy.cat_eyes_movies.entity.dto.UserDto;
import com.dgcsxy.cat_eyes_movies.entity.pojo.User;
import com.dgcsxy.cat_eyes_movies.service.UserService;
import org.springframework.stereotype.Service;

/**
 * @Author rokies
 * @DATE 2022/6/16 16:34
 * @Version 1.0
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {

    private final UserMapper userMapper;

    public UserServiceImpl(UserMapper userMapper) {
        this.userMapper = userMapper;
    }

    @Override
    public ResponseResult userLogin(User user) {
        User userLogin = userMapper.userLogin(user);
        if(!(userLogin.getUserPassword().equals(user.getUserPassword()))){
            return ResponseResult.FAILED("密码不正确");
        }else {
            return ResponseResult.SUCCESS(userLogin);
        }
    }

    @Override
    public ResponseResult userRegister(UserDto userDto) {
        if(!userDto.getUserPassword().equals(userDto.getUserPasswordEnter())){
            return ResponseResult.FAILED("密码与确认密码不正确");
        }
        User user = new User(userDto.getUserName(),userDto.getUserPassword(),userDto.getUserBirthday(),userDto.getUserEmail());
        int i = userMapper.userRegister(user);
        if(i==0){
            return ResponseResult.FAILED("注册失败");
        }
        return ResponseResult.SUCCESS("success");
    }

    @Override
    public ResponseResult userUpdate(User user) {
        int i = userMapper.userUpdate(user);
        if(i==0){
            return ResponseResult.FAILED("修改失败");
        }
        return ResponseResult.SUCCESS("success");
    }

}
